﻿using Microsoft.Practices.Mobile.ContainerModel;
using EventAggregationQuickStart;
using Microsoft.Practices.Composite.Events;

namespace SomeService
{
    public class SomeServiceConfigurator : IContainerModule
    {

        public SomeServiceConfigurator()
        {
        }

        #region IContainerModule Members

        public void Configure(Container container)
        {
            // Register the presenter and view types.
            RegisterTypes(container);
        }

        #endregion

        private void RegisterTypes(Container container)
        {
            // Register the factory function for the service.
            // Scope is container and descendant containers
            // Object is disposed when container is disposed
            container.Register<IServiceThatPublishesEvents>(
                c => new ServiceThatPublishesEvents(c.Resolve<IEventAggregator>())
                )
                .ReusedWithin(ReuseScope.Hierarchy)
                .OwnedBy(Owner.Container); 
        }
    }
}
